#!/bin/bash
#
# Copyright 2020 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.

set -eux

# parameter 1: pd host
# parameter 2: pd port
pd_host=${1}
pd_port=${2}
is_tls=${3:-false}

if [ "$is_tls" == "true" ]; then
	tso=$(run_cdc_cli tso query --pd=https://${pd_host}:${pd_port})
else
	tso=$(run_cdc_cli tso query --pd=http://${pd_host}:${pd_port})
fi

# make sure get tso only
# the tso got above is:
# "427768583921860609 PASS coverage: 2.7% of statements in github.com/pingcap/tiflow/..."
# and only "427768583921860609" is a real tso
echo $tso | awk -F " " '{print $1}'

set +x
